package com.testing.thread;

public class TestThreadStatus {

    public static void main(String[] args) {
        Thread thread = new Thread(() ->{
            for (int i = 0; i < 10; i++) {
                System.out.println("////");
            }
        });
        // 获取线程状态
        Thread.State state = thread.getState(); //新生状态
        System.out.println(state);
        thread.start(); // 运行状态
        System.out.println(state);

        while (state != Thread.State.TERMINATED){
            state = thread.getState(); // 更新线程状态
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(state);

            // 已经结束的线程不能被再次启动
            thread.start();
        }
    }
}
